﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ExpositionStrategy.cs" company="">
//   
// </copyright>
// <summary>
//   The strategy exposition.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using Systemathics.FrameWork.Interfaces;

namespace Systemathics.FrameWork
{
    public sealed class StrategyExposition : IExpositionNominal
    {
        private readonly Instrument[] Instruments;
        private readonly Expo Style;

        public StrategyExposition(Instrument[] instruments, Expo style)
        { 
            Instruments = instruments;
            Style = style;
        }

        public double TotalExposedNominal
        {
            get { return LongExposedNominal + ShortExposedNominal; }
        }
        public double Bias
        {
            get
            {
                double temp = Math.Abs(NetExposedNominal/TotalExposedNominal);
                return double.IsNaN(temp) ? 0 : temp;
            }
        }

        #region IExpositionNominal Members

        public double NetExposedNominal
        {
            get { return LongExposedNominal - ShortExposedNominal; }
        }
        public double LongExposedNominal
        {
            get
            {
                double temp = 0;
                foreach (Instrument i in Instruments)
                    temp += i[Style].LongExposedNominal;
                return temp;
            }
        }
        public double ShortExposedNominal
        {
            get
            {
                double temp = 0;
                foreach (Instrument i in Instruments)
                    temp += i[Style].ShortExposedNominal;
                return temp;
            }
        }
        public Decimal Realized
        {
            get
            {
                Decimal temp = 0;
                foreach (Instrument i in Instruments)
                    temp += i[Style].Realized;
                return temp;
            }
        }
        public Decimal UnRealized
        {
            get
            {
                Decimal temp = 0;
                foreach (Instrument i in Instruments)
                    temp += i[Style].UnRealized;
                return temp;
            }
        }
        public void Init()
        {
            foreach (Instrument i in Instruments)
                i[Style].Init();
        }

        #endregion
    }
}